<?php
//模型
class CourseTrainModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'course_train';
	}
	
	function get_list($arr,$page,$size){
		
		$where = "1";
		if(isset($arr['coach_id']) && !empty($arr['coach_id'])){
			$where .= " AND coach_id='{$arr['coach_id']}'";
		}
		if(isset($arr['uid']) && !empty($arr['uid'])){
			$where .= " AND user_id='{$arr['uid']}'";
		}
		if(isset($arr['name']) && !empty($arr['name'])){
			$where .= " AND name LIKE '%{$arr['name']}%'";
		}
		
		$res = $this->_where_get_list($where,$page,$size,"");
		$list = $res['list'];
		
		if($list){
			foreach($list as $key=>$val){
				$list[$key]['addtime'] = date('Y-m-d H:i:s',$val['addtime']);

			}
		}
		
		return array('list'=>$list,'count'=>$res['count']);
	}

	function get_info($id){
		$info = $this->_id_get_info($id);
		if(!$info){
			return false;
		}

		return $info;
	}
	function name_is_exits($name){
		$sql = "select id from ".$this->db->dbprefix.$this->table." where name='{$name}' limit 1";
		$query = $this->db->query($sql);
		$row  = $query->row_array();
		
		return $row?1:0;
	}
}

